home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus Special 17 / AMIGAplus Sonderheft 17 (1999)(ICP)(DE)[!].iso / Rexx / ShowVisage.dopus5 < prev    next >
Text File  |  1998-06-21  |  4KB  |  166 lines

  1. /* $VER: ShowVisage.dopus5 1.0 (19.7.97)
  2.  *
  3.  * Public domain by Magnus Holmgren.
  4.  *
  5.  * Shows the files selected in the source listers, by creating a temporary
  6.  * file list, and passing this to Visage via the LIST argument. This
  7.  * requires Visage 39.15 or better to work.
  8.  *
  9.  * Usage: ShowVisage.dopus5 PortName VisageOpts
  10.  *
  11.  * PortName   : Name of Opus ARexx port.
  12.  * VisageOpts : Any options to pass to Visage.
  13.  *
  14.  * Select "Run Asyncronously" if you like...
  15.  */
  16.  
  17.  
  18. /* Config section start */
  19.  
  20.     /* Complete path to the Visage executable. */
  21. VisagePath = 'Tools:View/Visage'
  22.     /* Path to drawer for the temporary file. Must end with ':' or '/' */
  23. TempPath   = 'T:'
  24.  
  25. /* Config section end */
  26.  
  27.  
  28. /* Set up */
  29. Lf = '0a'x
  30.  
  31. OPTIONS RESULTS
  32. PARSE ARG Port ' ' VisageOpts
  33.  
  34. /* Make sure arguments are reasonable */
  35. IF Port = '' | ~Show( 'P', Port ) THEN DO
  36.     /* Might not be visible when started incorrectly from Opus. ;) */
  37.     SAY 'ShowVisage.dopus5:'
  38.     SAY 'Not correctly called from Directory Opus 5!'
  39.     SAY 'See the ARexx-script for more information.'
  40.     RETURN
  41. END
  42.  
  43. /* Talk to Directory Opus */
  44. ADDRESS VALUE Port
  45.  
  46. /* Set break handling, since the script can take a while to finish */
  47. SIGNAL ON BREAK_C
  48.  
  49. /* Open temporary file, using a unique name */
  50. TempName = TempPath'ShowVisage.'Pragma( 'ID' )'.list'
  51.  
  52. IF ~Open( 'List', TempName, 'Write' ) THEN DO
  53.     CALL OpusMessage 'Couldn''t create temporary list file!'
  54.     RETURN
  55. END
  56.  
  57. /* Get all source listers */
  58. Lister Query Source
  59.  
  60. IF RC ~= 0 THEN DO
  61.     SIGNAL Failed
  62. END
  63.  
  64. Listers = RESULT
  65.  
  66. /* And process the source listers one by one */
  67. DO WHILE Listers ~= ''
  68.     PARSE VAR Listers Handle ' ' Listers
  69.  
  70.     IF ~SaveListerEntries( Handle ) THEN DO
  71.         SIGNAL Terminate
  72.     END
  73. END
  74.  
  75. /* Close generated file */
  76. IF ~Close( 'List' ) THEN DO
  77.     CALL OpusMessage 'Couldn''t write to temporary list file!'
  78.     SIGNAL Terminate
  79. END
  80.  
  81. /* We are now ready to display the files */
  82. ADDRESS COMMAND VisagePath' LIST "'TempName'" 'VisageOpts
  83. Command Delete '"'TempName'"' QUIET
  84.  
  85. RETURN
  86.  
  87.  
  88. Failed:
  89.     CALL OpusMessage 'Failed to get needed information!'
  90.  
  91.  
  92. /* Make a clean exit after break or error */
  93. BREAK_C:
  94.     Terminate:
  95.     CALL Close( 'List' )
  96.     Command Delete '"'TempName'"' QUIET
  97.     RETURN
  98.  
  99.  
  100. /* Save all selected entries in the specified lister to a file, and deselect
  101.  * the entries as we go
  102.  */
  103. SaveListerEntries:
  104.     PROCEDURE
  105.  
  106.     Handle = Arg( 1 )
  107.  
  108.     /* Get lister path. */
  109.     Lister Query Handle Path
  110.     FilePath = RESULT
  111.  
  112.     IF RC ~= 0 THEN DO
  113.         CALL OpusMessage 'Couldn''t get lister path!'
  114.         RETURN 0
  115.     END
  116.  
  117.     /* Make sure path is properly terminated */
  118.     IF Right( FilePath, 1 ) ~= ':' & Right( FilePath, 1 ) ~= '/' THEN DO
  119.         FilePath = FilePath'/'
  120.     END
  121.  
  122.     /* Get the selected entries */
  123.     Lister Query Handle SelEntries
  124.  
  125.     IF RC ~= 0 THEN DO
  126.         CALL OpusMessage 'Couldn''t get selected entries!'
  127.         RETURN 0
  128.     END
  129.  
  130.     Files = RESULT
  131.  
  132.     /* Here would probably be a good place to make the lister busy. However,
  133.      * it would make the script a bit more complicated, in order to ensure
  134.      * we don't leave a disabled lister behind us. And the busy stuff would
  135.      * only be useful with a fairly large number of files anyway...
  136.      */
  137.  
  138.     /* Iterate over all selected entries */
  139.     DO WHILE Files ~= ''
  140.         /* Extract one entry name */
  141.         PARSE VAR Files . '"' Name '"' Files
  142.  
  143.         /* Write name to file */
  144.         IF WriteLN( 'List', FilePath||Name ) = 0 THEN DO
  145.             CALL OpusMessage 'Couldn''t write to temporary list file!'
  146.             RETURN 0
  147.         END
  148.  
  149.         /* And deselect the file */
  150.         Lister Select Handle '"'Name'"' Off
  151.     END
  152.  
  153.     /* Refresh lister display */
  154.     Lister Refresh Handle
  155.     RETURN 1
  156.  
  157.  
  158. /* Show a message in an Opus requester, with a suitable "header" */
  159. OpusMessage:
  160.     PROCEDURE
  161.  
  162.     Lf = '0a'x
  163.     Message = 'ShowVisage.dopus5:'Lf||Lf||Arg(1)
  164.     DOpus Request '"'Message'"' 'OK'
  165.     RETURN
  166.